def print_file_info(file_name):
    """
    打印传入文件的内容
    :param file_name: 文件的名称
    :return: None
    """
    f = None
    try:
        f = open(file_name, 'r', encoding="UTF-8")
        for line in f:
            print(line, end='')
    except FileNotFoundError:
        print("该文件不存在")
    finally:
        if f:
            f.close()


def append_to_file(file_name, data):
    """
    在传入文件名的文件中追加指定内容
    :param file_name: 操作的文件名称
    :param data: 追加的内容数据
    :return: None
    """
    f = open(file_name, 'a', encoding="UTF-8")
    f.write(data)
    f.write('\n')
    f.close()


if __name__ == "__main__":
    name = "D:/Code/Python_code/python_learning/py_stage_1/text.txt"
    print_file_info(name)
    print_file_info("test.txt")
    append_to_file(name, "test...")
